﻿using Dapper;
using System.Data;
using System.Text.Json;
namespace BJoin.DapperExtension.Postgresql.TypeHandler
{
    public class JsonTypeHandler<T> : SqlMapper.TypeHandler<T>
      where T : class
    {
        public override T Parse(object value)
        {
            return JsonSerializer.Deserialize<T>((string)value);
        }

        public override void SetValue(IDbDataParameter parameter, T value)
        {
            parameter.Value = JsonSerializer.Serialize(value);
        }
    }
}
